#include "serial.h"
#include <qDebug>

serial::serial(QObject *parent) : QObject(parent)
{
//    connect(serialPort,SIGNAL(readyRead()),this,SLOT(read()));
}

serial::~serial()
{

}

void serial::open()
{
    qDebug()<<"serial" <<QThread::currentThreadId();
    serialPort = new QSerialPort();
    serialPort->setPortName("com3");
    serialPort->setBaudRate(115200);
    serialPort->setDataBits(QSerialPort::Data8);
    serialPort->setParity(QSerialPort::NoParity);
    serialPort->setStopBits(QSerialPort::OneStop);
    serialPort->setFlowControl(QSerialPort::NoFlowControl);
    connect(serialPort,SIGNAL(readyRead()),this,SLOT(read()));
    qDebug()<<"open"<<serialPort->open(QIODevice::ReadWrite);
}

void serial::write(QString data)
{
    qDebug()<<"write"<< serialPort->write("data.toLatin1()");
}

void serial::read()
{
    qDebug()<<"serial read" <<QThread::currentThreadId();
    qDebug()<<"read"<<serialPort->readAll();
}

